package com.ruoyi.house.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.house.domain.HseHouse;
import com.ruoyi.house.service.IHseHouseService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 房源Controller
 * 
 * @author ruoyi
 * @date 2024-07-08
 */
@RestController
@RequestMapping("/house/house")
public class HseHouseController extends BaseController
{
    @Autowired
    private IHseHouseService hseHouseService;

    /**
     * 查询房源列表
     */
    @PreAuthorize("@ss.hasPermi('house:house:list')")
    @GetMapping("/list")
    public TableDataInfo list(HseHouse hseHouse)
    {
        startPage();
        List<HseHouse> list = hseHouseService.selectHseHouseList(hseHouse);
        return getDataTable(list);
    }

    /**
     * 导出房源列表
     */
    @PreAuthorize("@ss.hasPermi('house:house:export')")
    @Log(title = "房源", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, HseHouse hseHouse)
    {
        List<HseHouse> list = hseHouseService.selectHseHouseList(hseHouse);
        ExcelUtil<HseHouse> util = new ExcelUtil<HseHouse>(HseHouse.class);
        util.exportExcel(response, list, "房源数据");
    }

    /**
     * 获取房源详细信息
     */
    @PreAuthorize("@ss.hasPermi('house:house:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(hseHouseService.selectHseHouseById(id));
    }

    /**
     * 新增房源
     */
    @PreAuthorize("@ss.hasPermi('house:house:add')")
    @Log(title = "房源", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HseHouse hseHouse)
    {
        return toAjax(hseHouseService.insertHseHouse(hseHouse));
    }

    /**
     * 修改房源
     */
    @PreAuthorize("@ss.hasPermi('house:house:edit')")
    @Log(title = "房源", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HseHouse hseHouse)
    {
        return toAjax(hseHouseService.updateHseHouse(hseHouse));
    }

    /**
     * 删除房源
     */
    @PreAuthorize("@ss.hasPermi('house:house:remove')")
    @Log(title = "房源", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(hseHouseService.deleteHseHouseByIds(ids));
    }
}
